/*
 * @FilePath     : /study_code/app.js
 * @Description  : express 服务器
 * @Date         : 2025-04-07 15:03:18
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-17 15:38:51
 */
const express = require('express')
const staticArray = require('./constants/static_array')
// layui 路由模块
const formSelectsRouter = require('./routes/layui/form-selects')
const xmSelectsRouter = require('./routes/layui/xm-select')
const uploadRouter = require('./routes/layui/upload')
const treeTableRouter = require('./routes/layui/tree-table')
// jquery 路由模块
const jqAjaxRouter = require('./routes/jquery/jq-ajax')

const app = express()
const port = 3000

// 中间件 --- start
// 静态托管
app.use('/assets', express.static('assets'))
app.use(express.static('node_modules')) // node_module 静态资源托管
staticArray.forEach(item => {
  app.use(`/${item}`, express.static(`${item}`))
})
app.use(express.json()) // 解析 json 格式参数
app.use(express.urlencoded({ extended: false })) // 注册 body 参数解析中间件
// 注册路由模块
app.use('/layui/form-selects', formSelectsRouter)
app.use('/layui/xm-selects', xmSelectsRouter)
app.use('/layui/upload', uploadRouter)
app.use('/layui/tree-table', treeTableRouter)
app.use('/jquery/jq-ajax', jqAjaxRouter)
// 中间件 --- end

// app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, () => {
  staticArray.forEach(item => {
    console.log(`http://localhost:${port}/${item}/index.html`)
  })
})

module.export = {
  port,
}
